<!DOCTYPE html>


<html lang="zh-CN">
  

    <head>
      <meta charset="utf-8" />
       
      <meta name="keywords" content="ES6、JS" />
       
      <meta name="description" content="ES6、JS" />
      
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title> 君书</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css"
      />
      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="君书" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      
<section class="cover">
    
  <div class="cover-frame">
    <div class="bg-box">
      <img src="/images/cover1.jpg" alt="image frame" />
    </div>
    <div class="cover-inner text-center text-white">
      <h1><a href="/">君书</a></h1>
      <div id="subtitle-box">
        
        <span id="subtitle"></span>
        
      </div>
      <div>
        
      </div>
    </div>
  </div>
  <div class="cover-learn-more">
    <a href="javascript:void(0)" class="anchor"><i class="ri-arrow-down-line"></i></a>
  </div>
</section>



<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js"></script>


<!-- Subtitle -->

  <script>
    try {
      var typed = new Typed("#subtitle", {
        strings: ['路还这么长', '这个年纪不该忧愁万分的', '生活嘛，慢慢来，所有的好运都在路上'],
        startDelay: 0,
        typeSpeed: 200,
        loop: true,
        backSpeed: 100,
        showCursor: true
      });
    } catch (err) {
      console.log(err)
    }
  </script>
  
<div id="main">
  <section class="outer">
  
  
  

<div class="notice" style="margin-top:50px">
    <i class="ri-heart-fill"></i>
    <div class="notice-content" id="broad"></div>
</div>
<script type="text/javascript">
    fetch('https://v1.hitokoto.cn')
        .then(response => response.json())
        .then(data => {
            document.getElementById("broad").innerHTML = data.hitokoto;
        })
        .catch(console.error)
</script>

<style>
    .notice {
        padding: 20px;
        border: 1px dashed #e6e6e6;
        color: #969696;
        position: relative;
        display: inline-block;
        width: 100%;
        background: #fbfbfb50;
        border-radius: 10px;
    }

    .notice i {
        float: left;
        color: #999;
        font-size: 16px;
        padding-right: 10px;
        vertical-align: middle;
        margin-top: -2px;
    }

    .notice-content {
        display: initial;
        vertical-align: middle;
    }
</style>
  
  <article class="articles">
    
    
    
    
    <article
  id="post-请求头中添加自定义数据"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2022/01/06/%E8%AF%B7%E6%B1%82%E5%A4%B4%E4%B8%AD%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE/"
    >请求头中添加自定义数据</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2022/01/06/%E8%AF%B7%E6%B1%82%E5%A4%B4%E4%B8%AD%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE/" class="article-date">
  <time datetime="2022-01-06T10:07:45.000Z" itemprop="datePublished">2022-01-06</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>当通过 xhr 发送请求，需要在请求头中携带自定义参数时，可分以下几种方式实现。</p>
<h2 id="使用原生-XMLHttpRequest"><a href="#使用原生-XMLHttpRequest" class="headerlink" title="使用原生 XMLHttpRequest"></a>使用原生 XMLHttpRequest</h2><p><code>XMLHttpRequest.setRequestHeader()</code> 是设置 HTTP 请求头的方法。此方法必须在 <code>open()</code> 和 <code>send()</code> 之间调用。如果多次对同一请求头进行赋值，则最终只会生成一个合并了多个值的请求头。</p>
<p>具体用法如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> xhr = <span class="keyword">new</span> XMLHttpRequest();</span><br><span class="line">xhr.open(url, method);</span><br><span class="line">xhr.setRequestHeader(<span class="string">&#x27;token&#x27;</span>, <span class="string">&#x27;xxxx&#x27;</span>);</span><br><span class="line">xhr.send(param);</span><br></pre></td></tr></table></figure>



<h2 id="使用-ajax"><a href="#使用-ajax" class="headerlink" title="使用 $.ajax"></a>使用 $.ajax</h2><p>当使用 <code>$.ajax(obj)</code> 实现请求的发送，如果请求头中需要携带特定参数，可以通过 obj 中的两个属性实现。</p>
<p>先大致了解下 obj 中有哪些重要的属性：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  type: <span class="string">&#x27;请求方式&#x27;</span>,</span><br><span class="line">  url: <span class="string">&#x27;请求路由&#x27;</span>,</span><br><span class="line">  data: <span class="string">&#x27;请求需要携带的数据&#x27;</span>,</span><br><span class="line">  dataType: <span class="string">&#x27;期望响应数据的格式&#x27;</span>,</span><br><span class="line">  beforeSend: <span class="string">&#x27;在发送请求之前可做的操作&#x27;</span>,</span><br><span class="line">  headers: <span class="string">&#x27;设置请求头内容&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>通过 <code>headers</code> 或者 <code>beforeSend</code> 属性就可以设置请求头内容，两个属性在具体开发中按自己喜好二选一即可。这两个属性值的具体格式如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  beforeSend: <span class="function"><span class="keyword">function</span>(<span class="params">request</span>) </span>&#123;</span><br><span class="line">    request.setRequestHeader(<span class="string">&#x27;token&#x27;</span>, <span class="string">&#x27;xxxx&#x27;</span>);</span><br><span class="line">  &#125;,</span><br><span class="line">  headers: &#123;</span><br><span class="line">    <span class="string">&#x27;token&#x27;</span>: <span class="string">&#x27;xxx&#x27;</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h2 id="设置请求头后访问接口报错"><a href="#设置请求头后访问接口报错" class="headerlink" title="设置请求头后访问接口报错"></a>设置请求头后访问接口报错</h2><p>当设置请求头后，访问接口出现报错，报错信息如下：</p>
<p><code>Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response.</code></p>
<p>此时后端接口需要如下设置：</p>
<p><code>res.setHeader(&#39;Access-Control-Allow-Headers&#39;, &#39;token&#39;);</code></p>
<p>附上一个完整的后端接口设置信息：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">doFilter</span><span class="params">(ServletRequest req, ServletResponse res, FilterChain chain)</span> <span class="keyword">throws</span> IOException, ServletException </span>&#123;</span><br><span class="line">    req.setAttribute(<span class="string">&quot;org.apache.catalina.ASYNC_SUPPORTED&quot;</span>, <span class="keyword">true</span>);</span><br><span class="line">    HttpServletResponse response = (HttpServletResponse) res;</span><br><span class="line">    response.setHeader(<span class="string">&quot;Access-Control-Allow-Origin&quot;</span>, ((HttpServletRequest) req).getHeader(<span class="string">&quot;Origin&quot;</span>));</span><br><span class="line">    response.setHeader(<span class="string">&quot;Access-Control-Allow-Methods&quot;</span>, <span class="string">&quot;POST, GET, OPTIONS, DELETE,PUT&quot;</span>);</span><br><span class="line">    response.setHeader(<span class="string">&quot;Access-Control-Max-Age&quot;</span>, <span class="string">&quot;3600&quot;</span>);</span><br><span class="line">    response.setHeader(<span class="string">&quot;Access-Control-Allow-Headers&quot;</span>, <span class="string">&quot;Content-Disposition,Origin, X-Requested-With, Content-Type, Accept,Authorization,id_token&quot;</span>);</span><br><span class="line">    response.setHeader(<span class="string">&quot;Access-Control-Allow-Credentials&quot;</span>,<span class="string">&quot;true&quot;</span>);</span><br><span class="line">    response.setHeader(<span class="string">&quot;Content-Security-Policy&quot;</span>, <span class="string">&quot;default-src &#x27;self&#x27; &#x27;unsafe-inline&#x27;; script-src &#x27;self&#x27;; frame-ancestors &#x27;self&#x27;; object-src &#x27;none&#x27;&quot;</span>);</span><br><span class="line">    response.setHeader(<span class="string">&quot;X-Content-Type-Options&quot;</span>, <span class="string">&quot;nosniff&quot;</span>);</span><br><span class="line">    response.setHeader(<span class="string">&quot;X-XSS-Protection&quot;</span>, <span class="string">&quot;1; mode=block&quot;</span>);</span><br><span class="line">    chain.doFilter(req, res);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ajax%E3%80%81%E8%AF%B7%E6%B1%82%E5%A4%B4/" rel="tag">ajax、请求头</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-浏览器跨域"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2022/01/06/%E6%B5%8F%E8%A7%88%E5%99%A8%E8%B7%A8%E5%9F%9F/"
    >浏览器跨域</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2022/01/06/%E6%B5%8F%E8%A7%88%E5%99%A8%E8%B7%A8%E5%9F%9F/" class="article-date">
  <time datetime="2022-01-06T09:54:40.000Z" itemprop="datePublished">2022-01-06</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>跨域是前端开发中不可避免的问题，当在开发中遇到跨域问题时，可以从以下几个方面入手排查：</p>
<ol>
<li>接口支持设置允许跨域的条件 <code>Access-Control-Allow-Origin</code></li>
<li>针对谷歌浏览器，可参照下面步骤进行设置<ol>
<li>新打开一个空白页，在浏览器地址栏输入 <code>chrome://flags/#block-insecure-private-network-requests</code></li>
<li>找到 <code>Block insecure private network requests.</code> 将其设置为 <code>Disabled</code></li>
<li>重启浏览器</li>
</ol>
</li>
</ol>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%B7%A8%E5%9F%9F%E3%80%81google/" rel="tag">跨域、google</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-float-布局"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/11/23/float-%E5%B8%83%E5%B1%80/"
    >float 布局</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/11/23/float-%E5%B8%83%E5%B1%80/" class="article-date">
  <time datetime="2021-11-23T12:43:11.000Z" itemprop="datePublished">2021-11-23</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>今天整理下 css 中 float 布局的应用及其应用的具体实现过程。css 中常见的布局有 float 布局和 flex 布局。今天着重整理 float 布局。</p> 
      <a class="article-more-link" href="/2021/11/23/float-%E5%B8%83%E5%B1%80/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css%E3%80%81float-%E5%B8%83%E5%B1%80/" rel="tag">css、float 布局</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-snabbdom库学习"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/28/snabbdom%E5%BA%93%E5%AD%A6%E4%B9%A0/"
    >snabbdom库学习</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/28/snabbdom%E5%BA%93%E5%AD%A6%E4%B9%A0/" class="article-date">
  <time datetime="2021-10-28T01:42:31.000Z" itemprop="datePublished">2021-10-28</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>学习 Vue 中了解到 Vue 中的虚拟 Dom 是仿照 snabbdom 库开发的，所以在学习 Vue 源码之前，先来学习 snabbdom 库是如何实现虚拟 Dom 以及 Diff 算法。先放上自己学习 snabbdom 库的思维导图。<br><img src="/2021/10/28/snabbdom%E5%BA%93%E5%AD%A6%E4%B9%A0/snabbdom.jpg" alt="snabbdom 库"></p> 
      <a class="article-more-link" href="/2021/10/28/snabbdom%E5%BA%93%E5%AD%A6%E4%B9%A0/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue%E3%80%81Diff-%E7%AE%97%E6%B3%95%E3%80%81%E8%99%9A%E6%8B%9F-Dom/" rel="tag">Vue、Diff 算法、虚拟 Dom</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-模拟Vue"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/27/%E6%A8%A1%E6%8B%9FVue/"
    >模拟Vue</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/27/%E6%A8%A1%E6%8B%9FVue/" class="article-date">
  <time datetime="2021-10-27T05:55:10.000Z" itemprop="datePublished">2021-10-27</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>在掌握了 Vue.js 的基础使用后，对 Vue 的特点也有了一定的了解。今天在 Vue 的基础章节学习结束后，尝试仿写 Vue 构造函数。</p> 
      <a class="article-more-link" href="/2021/10/27/%E6%A8%A1%E6%8B%9FVue/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue%E3%80%81Vue-%E7%B1%BB%E7%9A%84%E5%AE%9E%E7%8E%B0/" rel="tag">Vue、Vue 类的实现</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-Vue-响应式-发布订阅模式和观察者模式"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/23/Vue-%E5%93%8D%E5%BA%94%E5%BC%8F-%E5%8F%91%E5%B8%83%E8%AE%A2%E9%98%85%E6%A8%A1%E5%BC%8F%E5%92%8C%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F/"
    >Vue 响应式-发布订阅模式和观察者模式</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/23/Vue-%E5%93%8D%E5%BA%94%E5%BC%8F-%E5%8F%91%E5%B8%83%E8%AE%A2%E9%98%85%E6%A8%A1%E5%BC%8F%E5%92%8C%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F/" class="article-date">
  <time datetime="2021-10-23T08:47:39.000Z" itemprop="datePublished">2021-10-23</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>Vue 通过数据与视图的双向绑定，实现了数据变化后视图的更新以及视图变化对应数据的更新操作。Vue 通过观察者模式实现了该特点。</p> 
      <a class="article-more-link" href="/2021/10/23/Vue-%E5%93%8D%E5%BA%94%E5%BC%8F-%E5%8F%91%E5%B8%83%E8%AE%A2%E9%98%85%E6%A8%A1%E5%BC%8F%E5%92%8C%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue%E3%80%81%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">Vue、设计模式</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-vue-插件的开发（Vue-Router）"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/10/20/vue-%E6%8F%92%E4%BB%B6%E7%9A%84%E5%BC%80%E5%8F%91%EF%BC%88Vue-Router%EF%BC%89/"
    >vue 插件的开发（Vue-Router）</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/10/20/vue-%E6%8F%92%E4%BB%B6%E7%9A%84%E5%BC%80%E5%8F%91%EF%BC%88Vue-Router%EF%BC%89/" class="article-date">
  <time datetime="2021-10-20T06:54:08.000Z" itemprop="datePublished">2021-10-20</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p><code>Vue</code> 插件的存在为其添加了全局功能，该博文以 <code>vue-router</code> 插件为例，记录 vue 中插件的特点以及如何开发一个插件。</p> 
      <a class="article-more-link" href="/2021/10/20/vue-%E6%8F%92%E4%BB%B6%E7%9A%84%E5%BC%80%E5%8F%91%EF%BC%88Vue-Router%EF%BC%89/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue%E3%80%81Vue-%E6%8F%92%E4%BB%B6/" rel="tag">Vue、Vue 插件</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-webpack-模块打包工具"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/05/31/webpack-%E6%A8%A1%E5%9D%97%E6%89%93%E5%8C%85%E5%B7%A5%E5%85%B7/"
    >webpack-模块打包工具</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/05/31/webpack-%E6%A8%A1%E5%9D%97%E6%89%93%E5%8C%85%E5%B7%A5%E5%85%B7/" class="article-date">
  <time datetime="2021-05-31T05:34:13.000Z" itemprop="datePublished">2021-05-31</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p><code>webpack</code> 是前端模块常用的打包工具，由于其生态完整，在插件的配合下，功能强大。所以在前端的项目中，在生产环境和开发环境中会通过不同的插件配置，帮助开发者搭建良好的开发体系。</p>
<p><code>webpack</code> 与 <code>grunt、gulp</code> 等构件工具的不同：</p>
<ol>
<li><code>webpack</code> 是一个模块打包工具。将多个文件打包成一个文件，减少生产环境上资源的请求次数</li>
<li><code>grunt/gulp</code> 是自动化构建工具。主要用于对 <code>js/css/html</code> 等资源转换成浏览器可加载的资源</li>
</ol>
<p><code>webpack</code> 工具处理的任务：</p>
<ol>
<li><code>打包文件</code>：将多个有关联的文件打包形成一个文件，减少生产环境中的资源请求次数</li>
<li><code>加载不同类型的资源</code>：<code>webpack</code> 可通过配合使用 <code>loader</code> 实现不同类型文件的加载</li>
<li><code>对资源进行压缩、清除、复制、tree-shaking 等操作</code>：<code>webpack</code> 可配合 <code>plugin</code> 实现不同的操作要求</li>
</ol> 
      <a class="article-more-link" href="/2021/05/31/webpack-%E6%A8%A1%E5%9D%97%E6%89%93%E5%8C%85%E5%B7%A5%E5%85%B7/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-工程化-构建工具"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/05/20/%E5%B7%A5%E7%A8%8B%E5%8C%96-%E6%9E%84%E5%BB%BA%E5%B7%A5%E5%85%B7/"
    >工程化--构建工具</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/05/20/%E5%B7%A5%E7%A8%8B%E5%8C%96-%E6%9E%84%E5%BB%BA%E5%B7%A5%E5%85%B7/" class="article-date">
  <time datetime="2021-05-20T03:35:38.000Z" itemprop="datePublished">2021-05-20</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>构建工具 <code>Grunt</code> 和 <code>Gulp</code> 的作用：</p>
<ol>
<li>浏览器不支持某些语法，可通过构建工具将其转换为浏览器支持的语法</li>
<li>对于资源文件，可进行压缩，减小文件的体积</li>
<li>可将多个文件打包到一个文件中，减少资源的请求</li>
<li>…</li>
</ol>
<p>下面总结两个工具的使用以及区别。</p> 
      <a class="article-more-link" href="/2021/05/20/%E5%B7%A5%E7%A8%8B%E5%8C%96-%E6%9E%84%E5%BB%BA%E5%B7%A5%E5%85%B7/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96/" rel="tag">前端工程化</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
    <article
  id="post-工程化-脚手架"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2021/05/20/%E5%B7%A5%E7%A8%8B%E5%8C%96-%E8%84%9A%E6%89%8B%E6%9E%B6/"
    >工程化--脚手架</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2021/05/20/%E5%B7%A5%E7%A8%8B%E5%8C%96-%E8%84%9A%E6%89%8B%E6%9E%B6/" class="article-date">
  <time datetime="2021-05-20T02:02:24.000Z" itemprop="datePublished">2021-05-20</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p><strong>工程化是一个前端项目的整体架构和规划</strong>。项目从开发到上线，每个环节都会存在各种开发规范以及开发难点。例如：</p>
<ol>
<li>开发前项目结构目录规划</li>
<li>团队协作开发中代码风格的约定</li>
<li>开发中浏览器对扩展语法的不支持</li>
<li>页面渲染对接口数据的依赖</li>
<li>浏览器热部署的调试功能</li>
<li>上线时代码的打包压缩</li>
<li>…</li>
</ol>
<p>为了解决项目中的一系列问题，前辈们总结经验，整合了一些集成化的，被行业认可的工具。所以我们在开发的时候，只需集成这些工具，正确使用即可解决这些繁琐重要的任务，把更多精力留给业务开发。今天先来总结下脚手架的使用。</p> 
      <a class="article-more-link" href="/2021/05/20/%E5%B7%A5%E7%A8%8B%E5%8C%96-%E8%84%9A%E6%89%8B%E6%9E%B6/"
        >继续阅读</a
      >
       
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96/" rel="tag">前端工程化</a></li></ul>

    </footer>
  </div>

   
    
</article>

    
  </article>
  

  
  <nav class="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/2/">上一页</a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><span class="page-number current">3</span><a class="page-number" href="/page/4/">4</a><a class="extend next" rel="next" href="/page/4/">下一页</a>
  </nav>
  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2022
        <i class="ri-heart-fill heart_icon"></i> 小付君
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="君书"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->

<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>